package com.example.testing.flags;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.example.testing.R;
import com.example.testing.launchmode.SingleInstanceActivity;
import com.example.testing.launchmode.SingleTaskActivity;
import com.example.testing.launchmode.SingleTopActivity;
import com.example.testing.launchmode.StandardActivity;

/**
 * 如果单独设置FLAG_ACTIVITY_NEW_TASK，并不能达到xml里singleTask的效果
 * 要想达到xml里singleTask效果，需要Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP组合使用
 * 不过这时候，也不是完全等同于singleTask模式，因为就算xml中指定了taskAffinity属性，也不能开辟新的任务栈
 */
public class NewTaskActivity extends Activity {
    private static final String TAG = "NewTaskActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        Log.e(TAG, "onCreate: ");
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_flags_newtask);
        findViewById(R.id.tv_flags).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(NewTaskActivity.this, NewTaskActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
                startActivity(intent);
            }
        });
    }

    @Override
    protected void onNewIntent(Intent intent) {
        Log.e(TAG, "onNewIntent: ");
        super.onNewIntent(intent);
    }
}
